Skip to main content

Scripts

  • optional

A Template Package can include scripts to be deployed to Twinit by configuring script definitions in the manifest.scripts array and matching files containing the JavaScript content of the scripts in the packages 'scripts' folder.

A script definition should include the _name, _description, _shortName, and _userType for the script like so:

// manifest.json"scripts": [   {      "_name": "Sample Script",      "_shortName": "samplescr",      "_description": "A sample script",      "_userType": "sample-scr"   }]

You may include as many script definitions in the scripts array as needed.

Each script definition must map to an .mjs file in the package's scripts folder, where the _name of the script definition matches the name of the .mjs file.

Complete Example:#

// manifest.json{   "Template Name": "Water Treatment Operations Digital Twin",   "Template Version": "1.0.5",   "scripts": [      {         "_name": "Sample Script",         "_shortName": "samplescr",         "_description": "A sample script",         "_userType": "sample-scr"      }   ]}
// Package Zip FileWater Treatment Template.zip /||-- scripts /|   |-- Sample Script.mjs||-- manifest.json
//Sample Script.mjsexport async script(input, libraries, ctx, callback) {
   // twinit script
}

Deploying Scripts#

When the Template Package is deployed, if the defined script does not exist it will be created. If a script with the same _name already exists, a new version of the script will be created.

Deploying multiple versions of the same script is also possible. See Support for Deploying Versioned Items